import useWebSocket from "./easyWebSocket";
 
const { send, addMessageListener } = useWebSocket("ws://localhost:3000");
 
 useEffect(() => {
    send(['首页已连接','/api/homePage/Interface']);
    // 添加消息监听器
    addMessageListener((message) => {
      console.log("收到消息：", message);
      if (message === "/api/Interface/userInfo") {
        setDataSource([
          {
            key: "1",
            name: nanoid(),
            age: nanoid(),
            address: nanoid(),
          },
          {
            key: "2",
            name: nanoid(),
            age: nanoid(),
            address: nanoid(),
          },
        ]);
      }
    });
 
    return () => {
      console.log("组件卸载，WebSocket 连接已关闭");
    };
  }, []);